package servlet;

import pojo.Function;
import pojo.User;
import service.LoginService;
import service.serviceImpl.LoginServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017-11-20.
 */
public class LoginServlet extends BaseServlet {
    LoginService loginService =null;
    public String login(HttpServletRequest request, HttpServletResponse response) throws SQLException, ServletException, IOException {
        HttpSession session;
        String username=request.getParameter("username");
        String password=request.getParameter("password");
        loginService =new LoginServiceImpl();
        User user= loginService.checkLogin(username,password);
        if (user!=null){
            session= request.getSession();
            session.setAttribute("userInfo",user);
            return "/home?method=home";
        }else {
            request.setAttribute("meg","用户密码不一致，请重新登录");
            return "/jsp/index.jsp";

        }

    }
    public String logout(HttpServletRequest request, HttpServletResponse response){
        //销毁session
        HttpSession session= request.getSession();
        session.invalidate();
        return "/jsp/index.jsp";
    }

}
